-- @owner: @li-xin12345
-- @date: 2023/7/31
-- @testpoint: 普通非压缩表，修改compresstype=2，compress_chunk_size为不同值，部分步骤合理报错
-- @history: Modified by li-xin12345 2025.2.12：研发代码变更，取消参数控制，适配用例

--step1:建普通表并插入数据;expect:成功
drop table if exists t_alter_rowcompress_0012 cascade;
create table t_alter_rowcompress_0012(columnone integer ,columntwo char(50) ,columnthree varchar(50) ,columnfour integer ,columnfive char(50) ,columnsix varchar(50) ,columnseven char(50) ,columneight char(50) ,columnnine varchar(50) ,columnten varchar(50) ,columneleven char(50) ,columntwelve char(50) ,columnthirteen varchar(50) ,columnfourteen char(50) ,columnfifteem varchar(50));
insert into t_alter_rowcompress_0012 values(generate_series(0, 1000),'test','abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwx', 2, 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwx', 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwx', 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwx', 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwx', 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwx', 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwx', 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwx', 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwx', 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwx', 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwx', 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwx');

drop function if exists compress_func_findpath(character varying);
create or replace function compress_func_findpath(character varying)
returns character varying
language plpgsql
as
$body$
declare
relpath character varying;
begin
relpath = (select pg_relation_filepath(relname::regclass) from pg_class where relname = $1);
return relpath;
end;
$body$;
/

--step2:修改压缩参数compresstype=2,compress_chunk_size=512;expect:成功
alter table t_alter_rowcompress_0012 set (compresstype=2,compress_chunk_size=512);
checkpoint;
select is_compress, file_count, logic_size, physic_size, compress_ratio from pg_catalog.compress_ratio_info(compress_func_findpath('t_alter_rowcompress_0012'));
select chunk_size, algorithm from pg_catalog.compress_address_header('t_alter_rowcompress_0012', 0);

--step3:修改压缩参数compresstype=2,compress_chunk_size=1024;expect:成功
alter table t_alter_rowcompress_0012 set (compresstype=2,compress_chunk_size=1024);
checkpoint;
select is_compress, file_count, logic_size, physic_size, compress_ratio from pg_catalog.compress_ratio_info(compress_func_findpath('t_alter_rowcompress_0012'));
select chunk_size, algorithm from pg_catalog.compress_address_header('t_alter_rowcompress_0012', 0);

--step4:修改压缩参数compresstype=2,compress_chunk_size=2048;expect:成功
alter table t_alter_rowcompress_0012 set (compresstype=2,compress_chunk_size=2048);
checkpoint;
select is_compress, file_count, logic_size, physic_size, compress_ratio from pg_catalog.compress_ratio_info(compress_func_findpath('t_alter_rowcompress_0012'));
select chunk_size, algorithm from pg_catalog.compress_address_header('t_alter_rowcompress_0012', 0);

--step5:修改压缩参数compresstype=2,compress_chunk_size=4096;expect:成功
alter table t_alter_rowcompress_0012 set (compresstype=2,compress_chunk_size=4096);
checkpoint;
select is_compress, file_count, logic_size, physic_size, compress_ratio from pg_catalog.compress_ratio_info(compress_func_findpath('t_alter_rowcompress_0012'));
select chunk_size, algorithm from pg_catalog.compress_address_header('t_alter_rowcompress_0012', 0);

--step6:修改压缩参数compresstype=2,compress_chunk_size为取值范围外的值;expect:合理报错
alter table t_alter_rowcompress_0012 set (compresstype=2,compress_chunk_size=511);
alter table t_alter_rowcompress_0012 set (compresstype=2,compress_chunk_size=3000);
alter table t_alter_rowcompress_0012 set (compresstype=2,compress_chunk_size=5000);

--step7:修改压缩参数compresstype=2,compress_chunk_size为无效值;expect:合理报错
alter table t_alter_rowcompress_0012 set (compresstype=2,compress_chunk_size='test');
alter table t_alter_rowcompress_0012 set (compresstype=2,compress_chunk_size=1.1);

--step8:清理环境;expect:成功
drop table if exists t_alter_rowcompress_0012;